As is known in the art, object-oriented programming (OOP) is a programming paradigm that encapsulates data behavior into self-sufficient reusable objects which include data and operations on the data. In particular, in OOP programmers use data classes to define abstract characteristics of a domain object. For example, programmers may represent a vehicle using a data class that includes vehicle attributes, such as a number of wheels, an exterior color, a velocity, etc., as well as vehicle operations such as moving and stopping.
OOP includes features that may be particularly attractive to programmers. For example, OOP data inheritance allows programmers to design data class hierarchies for a particular domain. The data class hierarchies may include classes that inherit particular characteristics of a parent class, as well as override certain generic behaviors for specific behaviors germane to a subclass.
As an example, a programmer can create a data class hierarchy to represent dogs and individual breeds of dogs. The dog data class hierarchy can define a parent or base class to include attributes and behaviors shared by all dog breeds. For example, the dog class may include a breed of dog, a dog name, and an ability to bark. Programmers may then define subclasses of the dog class to further differentiate breeds from each other. For example, a subclass may be defined for Golden Retriever, Chihuahua, Beagle, etc., that includes specific behaviors, such as whether the breed has a coat of fur or hair.
In OOP, the attributes and behaviors of the base class are conveniently propagated to the subclasses, which can reduce program time and cost as well as simplify domain design. Polymorphism may be used to override common behaviors. For example, most animals can make a noise. In a base animal data class, an operation called “make_noise( )” may be used to perform this common behavior. A pig subclass may override the make_noise( ) operation to elicit an “oink( )” operation.
An instance of a data class includes an actual data class object created at runtime that includes the actual values of the data class object, such as an exterior color of an automobile, a velocity of the automobile, etc. The data class operations, so-called methods, may be used to retrieve and/or modify the data class attributes. For example, a get and a set method may be used to respectively retrieve the exterior color and to set the exterior color of an instance of a vehicle data class.
As is also known in the art, a JavaBean is a reusable software component written in the Java® programming language and with OOP techniques in mind (Java is a registered trademark of Sun Microsystems, Inc. of Santa Clara, Calif.). A JavaBean encapsulates many data class objects into a single object (a so-called “bean”) that can conveniently be packaged and transferred from platform to platform. The following code segment is an example of a JavaBean called “DogBean.java”:
public class DogBean implements java.io.Serializable {private String breed;//a data field of the DogBeanpublic DogBean( ){ } //constructor to create andreturn a new DogBeanobjectpublic String getBreed( ){ return this.breed;}//get breed data fieldpublic void setBreed(final String breed){ this.breed =breed;}//set breeddata field}
As can be seen, the JavaBean is serializable so that a state of the DogBean may be saved and recalled, and includes a constructor to define an instance of the DogBean, and get and set operations for every defined data field, here, a string called “breed.”
JavaBean conventions require that every bean class define getter and setter methods (i.e., a get( ) and a set( ) method) to respectively get and set data fields of the bean. The following code segment may be used to test the DogBean and execute the get and set methods:
public class TestDogBean {public static void main(String{ } args) {DogBean dog = new DogBean( );// create aDogBean instancedog.setBreed(“Black Labrador”);//setthe breed data field// Output the breedSystem.out.print(dog.getBreed( ));//output usinggetter method}}
In the conventional art, programmers write code to update JavaBean objects and, in particular, data fields of a JavaBean object. Programmers must write separate lines of code to individually address whether each data field is to be modified and, if so, modify the data field. As an example, a JavaBean object may include three data fields as follows:
JavaBean Object OldObject {Data A = X;Data B = Y:Data C = Z;}
Here, Data A, Data B, and Data C refer to there data fields of Object OldObject having respective values of X, Y, and Z. A JavaBean update object UpdateObject may include an update to one of the data fields as follows:
JavaBean Object UpdateObject {Data A = null;Data B = YY:Data C = null;}
Here, data fields Data A and Data C are equal to “null,” indicating no update to these fields, whereas data field Data B is to be updated to “YY.” An update method to perform the update to Object OldObject includes the following code segment:
If(UpdateObject.getDataA( )!=null){
OldObject.setDataA(UpdateObject.getDataA( ));}
If(UpdateObject.getDataB( )!=null){
OldObject.setDataB(UpdateObject.getDataB( ));}
If(UpdateObject.getDataC( )!=null){
OldObject.setDataA(UpdateObject.getDataC( ));}
As can be seen, a separate “if” statement is required for each data field. Although the above example is relatively simple, a real-world scenario involving complex, many-tiered object hierarchies and thousands of data classes and their respective data fields may require a programmer to write and test (and modify) tens-of-thousands of lines of code in order to successfully implement a JavaBean. This can significantly increase development time, effort, and cost, as well as significantly increase product support and maintenance requirements. Furthermore, as the code base increases in size, so does the opportunity for code defects due to programmer error.